package main.interaction
{
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	
	import main.util.Util;
	
	public class ScreenRegions extends Sprite
	{
		
		public static const NORTH:String = "north";
		public static const SOUTH:String = "south";
		public static const EAST:String = "east";
		public static const WEST:String = "west";
		
		private var marginNorth:Number = 50;
		private var marginSouth:Number = 50;
		private var marginEast:Number = 50;
		private var marginWest:Number = 50;
		
		private var regionNorth:Region = new Region(NORTH);
		private var regionSouth:Region = new Region(SOUTH);
		private var regionEast:Region = new Region(EAST);
		private var regionWest:Region = new Region(WEST);
		
		private var regions:Dictionary = new Dictionary();

		private var w:Number;
		private var h:Number;
		
		public function getRegion(name:String):Region {
			return Util.exists(regions[name]);
		}
		
		public function ScreenRegions() {
			regions[NORTH] = regionNorth;
			regions[SOUTH] = regionSouth;
			regions[EAST] = regionEast;
			regions[WEST] = regionWest;
			for each(var r:Region in regions) {
				addChild(r);
			}
		}
		


		public function resize(w:Number, h:Number):void {
			this.w = w;
			this.h = h;
			refresh();
		}
		
		public function refresh():void {
			regionNorth.setSize(w, marginNorth, 
				regionWest.enabled ? marginWest : 0, 
				regionEast.enabled ? marginEast : 0);
			
			regionSouth.setSize(w, marginSouth,
				regionEast.enabled ? marginEast : 0,
				regionWest.enabled ? marginWest : 0);
			regionSouth.rotation = 180;
			regionSouth.x = w;
			regionSouth.y = h;
			
			regionEast.setSize(h, marginEast,
				regionNorth.enabled ? marginNorth : 0,
				regionSouth.enabled ? marginSouth : 0);
			regionEast.rotation = 90;
			regionEast.x = w;
			
			regionWest.setSize(h, marginWest,
				regionSouth.enabled ? marginSouth : 0,
				regionNorth.enabled ? marginNorth : 0);
			regionWest.rotation = -90;
			regionWest.y = h;
		}
		

	}
}